import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

import 'action.dart';
import 'state.dart';

Effect<LoginPageState> buildEffect() {
  return combineEffects(<Object, Effect<LoginPageState>>{
    Lifecycle.initState: _init,
  });
}

void _init(dynamic action, Context<LoginPageState> ctx) {
  final String username = 'admin';
  final String password = 'qwe123,./';

  ctx.dispatch(
    LoginPageActionCreator.init(
      LoginPageState(
        formKey: GlobalKey<FormBuilderState>(),
        usernameController: TextEditingController.fromValue(
          TextEditingValue(
            text: username,
            selection: TextSelection.collapsed(offset: username.length),
          ),
        ),
        passwordController: TextEditingController.fromValue(
          TextEditingValue(
            text: password,
            selection: TextSelection.collapsed(offset: password.length),
          ),
        ),
      ),
    ),
  );
}
